package com.ckd.flyingtrip.charge.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.activity.BaseActivity;
import com.ckd.flyingtrip.dialog.PayWayDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/*
 * 支付信息
 * */
public class OvertimePaymentActivity extends BaseActivity {


    @BindView(R.id.toolber_color_title)
    TextView title;
    @BindView(R.id.tv_msg)
    TextView tvMsg;
    //    @BindView(R.id.tv_overtime)
//    TextView tvOvertime;
//    @BindView(R.id.tv_overmoney)
//    TextView tvOvermoney;
    private PayWayDialog.Builder pb;

    private String userId;
    private String money;  //待支付金额
    private String overtime; //超时时间
    private String batteryType; //电池类型 ( 0 磷酸铁锂电池、1 铅酸电池)
    private String batteryV; // 48、60、72
    private String cabinetDoor; //柜门
    private String cabinet; //换电柜编码
    private String overtimeMsg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_overtime_pay);
        ButterKnife.bind(this);

        initView();

    }

    private void initView() {
        title.setText("超时支付");

        Intent intent = getIntent();
        userId = intent.getStringExtra("userId");
        money = intent.getStringExtra("money");
        overtime = intent.getStringExtra("overtime");
        batteryType = intent.getStringExtra("batteryType");
        batteryV = intent.getStringExtra("batteryV");
        cabinetDoor = intent.getStringExtra("cabinetDoor");
        cabinet = intent.getStringExtra("cabinet");
        overtimeMsg = intent.getStringExtra("overtimeMsg");

        tvMsg.setText(overtimeMsg);

    }

    @OnClick({R.id.toolber_color_back, R.id.btn_pay})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.toolber_color_back:
                finish();
                break;
            case R.id.btn_pay:
                pb = new PayWayDialog.Builder(OvertimePaymentActivity.this,
                        new PayWayDialog.Builder.PriorityListener() {
                            @Override
                            public void refreshPriorityUI(String f) {
                                volleyQueryFei(userId, f);
                                pb.create().dismiss();
                            }
                        });
                pb.create().show();
                break;
        }
    }

    private void volleyQueryFei(String id, String type) {
        if (type.equals("weixin")) {
//            Weixin weixin = new Weixin(GoumaiActivity.this, "");
//            weixin.volleyDINGDAN(id);
            dismisProgressDialog();
        } else if (type.equals("alipay")) {
            createLoadingDialog(this, "正在支付中...", true);
            ChargeAlipay alipay = new ChargeAlipay(OvertimePaymentActivity.this, "", new ChargeAlipay.payInterface() {
                @Override
                public void paySuccess() {
                    //支付成功
                    Intent intent = new Intent();
                    setResult(2001, intent);
                    finish();
                }

                @Override
                public void payFail() {
//                    finish();
                    //支付失败
                }
            });
            alipay.volleyOvertimePay(id, money, overtime, batteryType, batteryV, cabinetDoor, cabinet);
        }
    }
}
